layui.define(['layer', 'jquery'], function () { //提示：模块也可以依赖其它模块，如：layui.define('layer', callback);
  var jQuery = layui.jquery,
  layer=layui.layer,
      $ = jQuery,
      trss = {};
      $(document).ready(function(){
        if(localStorage.getItem("wkToken")==null){
            window.location.href="../login.html";
            return;
        };
        //AuthToken();
        });
    function GetFunByUser(){

    }
    HavePermission=function(d){
        var roles=new Array();
        roles=localStorage.getItem("menus");
        if(roles.indexOf(d)==-1){
            return false;
        }
        return true;
    }
    function AuthToken(){
       $.ajax({
           url: '/api/home/authToken',
           type: 'get',
           async: false,
           contentType: "application/json",
           beforeSend:function(request){
               request.setRequestHeader("token",localStorage.getItem("wkToken"));
           },
           success: function (value) {
              if(value.resultCode==401){
                   localStorage.removeItem("wkToken");
                   window.location.href = "../login.html";
              }
           },
           error: function (xhr) {
               layer.msg("错误提示： " + xhr.status + " " + xhr.statusText);
           }
       });
    }
    AxajGet= function (url,callbackurl,successFun){
       $.ajax({
           url: url,
           type: 'get',
           async: false,
           contentType: "application/json",
           beforeSend:function(request){
               request.setRequestHeader("token",localStorage.getItem("wkToken"));
           },
           success: function (value) {
              if(value.resultCode==401){
                   localStorage.removeItem("wkToken");
                   localStorage.removeItem("userName");
                   localStorage.removeItem("menus");
                   window.location.href = "../../login.html";
                   return ;
              }
              else if(value.resultCode==403){
                layer.msg("您没有操作权限");
                return ;
              }
              if (value.resultCode == 0) {
                  successFun(value.data);
               } 
              else{
               layer.msg("错误提示：" +value.resultMsg);
              }
               
           },
           error: function (xhr) {
               layer.msg("错误提示： " + xhr.status + " " + xhr.statusText);
           }
       });
    }
    AxajPost=function (url,data,msg,callbackurl,successFun){
       $.ajax({
           url: url,
           type: 'post',
           async: false,
           contentType: "application/json",
           beforeSend:function(request){
               request.setRequestHeader("token",localStorage.getItem("wkToken"));
           },
           data:JSON.stringify(data) ,
           dataType: 'json',
           success: function (value) {
               if(value.resultCode==401){
                   localStorage.removeItem("wkToken");
                   localStorage.removeItem("userName");
                   localStorage.removeItem("menus");
                   window.location.href = "../../login.html";
                   return ;
               }
               else if(value.resultCode==403){
                layer.msg("您没有操作权限");
                return ;
              }
               if (value.resultCode == 0) {
                   if(msg!=undefined||msg!=null)
                   layer.msg(msg);
                  if(successFun!=undefined||successFun!=null)
                   successFun(value.data);
               } else{
                   layer.msg(value.resultMsg);
                   return false;
               }
           },
           error: function (xhr) {
               layer.msg("错误提示： " + xhr.status + " " + xhr.statusText);
           }
       });
    }
    });
        